package com.mindata.blockchain.core.sqlparser;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.mindata.blockchain.block.Operation;
import com.mindata.blockchain.common.CommonUtil;
import com.mindata.blockchain.core.model.MessageEntity;
import com.mindata.blockchain.core.model.OrderEntity;
import com.mindata.blockchain.core.model.TicketEntity;
import com.mindata.blockchain.core.repository.OrderRepository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author 王鹏
 */
@Service
public class OrderSqlParser extends AbstractSqlParser<OrderEntity>{
    @Resource
    private OrderRepository orderRepository;


    @Override
    void parse(byte operation, String id, OrderEntity entity) {
        if (operation == Operation.ADD){
            entity.setCreateTime(CommonUtil.getNow());
            entity.setOrderId(id);
            orderRepository.save(entity);
        }else if (operation == Operation.UPDATE){
//            OrderEntity orderEntity = orderRepository.findByOrderId(id);
//            BeanUtil.copyProperties(entity, orderEntity, CopyOptions.create().setIgnoreNullValue(true).setIgnoreProperties("id", "createTime"));
//            orderRepository.save(orderEntity);
        }
    }

    @Override
    Class getEntityClass() {
        return OrderEntity.class;
    }
}
